<script src="<?php echo $baseurl?>public/ckeditor/ckeditor.js"></script>
<script src="<?php echo $baseurl?>public/ckeditor/adapters/jquery.js"></script>

<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="">Home</a> <span class="divider">/</span></li>
        <li class="active">G-People</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Sửa thông tin ưu đãi</h1> <span></span>
</div><!--pagetitle-->

<div class="maincontent">
<?php if(validation_errors()): ?>
    <div class="alert alert-error" style="margin: 10px 10px 10px 40px;">
      <button data-dismiss="alert" class="close" type="button">×</button>
      <?php echo validation_errors(); ?>
    </div>
<?php endif;?>
	<div class="contentinner content-dashboard">
    <?php $attr = array('class' => 'stdform'); echo form_open_multipart('', $attr)?>
        <p>
        	<label>Tên ưu đãi</label>
            <span class="field"><input type="text" name="title" class="input-xlarge" placeholder="Nhập tên ưu đãi" value="<?php echo $data ? stripslashes($data['title']) : ''?>"/></span>
        </p>
        <p>
        	<label>Ảnh ưu đãi</label>
            <span class="field">
                <img src="<?php echo $data ? $imgbase.$data['image'] : ''?>" id="img_incens_show_" style="display: inline-block; vertical-align: middle;width: 69px;height: 69px;border: 1px solid #CCC;background: #CCC;" />
                <input type="hidden" name="img_incens_hd_" id="img_incens_hd_" value="" />
                <input type="hidden" name="img_incens_verify" id="img_incens_verify" value="<?php echo $data ? $data['image'] : ''?>" />
                <input type="hidden" name="img_incens_hd_check" id="img_incens_hd_check" value="<?php echo $data ? $data['image'] : ''?>" />
                <input class="uniform-file" type="file" name="fileupload" id="img_incens_" onchange="convertimage('img_incens_', 'img_incens_hd_', 'img_incens_show_', 'img_incens_hd_check');" value="" />
				( Ảnh jpg, Kích thước 260x260, tối đa 2Mb )
            </span>
        </p>
        <p>
        	<label>Ảnh bài viết</label>
            <span class="field">
                <img src="<?php echo $data ? $imgbase.$data['slide_image'] : ''?>" id="img1_incens_show_" style="display: inline-block; vertical-align: middle;width: 69px;height: 69px;border: 1px solid #CCC;background: #CCC;" />
                <input type="hidden" name="img1_incens_hd_" id="img1_incens_hd_" value="" />
                <input type="hidden" name="img1_incens_verify" id="img1_incens_verify" value="<?php echo $data ? $data['slide_image'] : ''?>" />
                <input type="hidden" name="img1_incens_hd_check" id="img1_incens_hd_check" value="<?php echo $data ? $data['slide_image'] : ''?>" />
                <input class="uniform-file" type="file" name="fileupload1" id="img1_incens_" onchange="convertimage('img1_incens_', 'img1_incens_hd_', 'img1_incens_show_', 'img1_incens_hd_check');" value="" />
				( Ảnh jpg, Kích thước 600x300, tối đa 2Mb )
            </span>
        </p>
        <p>
        	<label>Mô tả</label>
            <span class="field"><input type="text" name="summary" class="input-xlarge" placeholder="Mô tả" value="<?php echo $data ? $data['summary'] : ''?>"/></span>
        </p>
        <p>
        	<label>Nội dung</label>
            <span class="field"><textarea id="content_" name="content" cols="80" rows="5" class="span5 tinymce"><?php echo $data ? $data['content'] : ''?></textarea></span>
        </p>
        <p>
            <label>Chọn coupon dành cho ưu đãi</label>
            <?php echo $fview->selectTypesx($ecoupon, @$data['ecoupon'] ? $data['ecoupon'] : 0, 'sl_coupon', 'Chọn coupon');?>
        </p>
        <p>
        	<label>Chọn loại ưu đãi</label>
            <span class="formwrapper">
             <?php echo $fview->inputRadio(array(array('id' => 'x1', 'value' => 0, 'label' => 'Cố định &nbsp; &nbsp;'), array('id' => 'x2', 'value' => 1, 'label' => 'Hàng tháng')), $data['type'], 'incentives_type');?>
            </span>
        </p>
        <p id="time_select_box">
        	<label>Thời gian ưu đãi</label>
            <span class="field">
                <?php echo $fview->selectType($month, @$data['month'] ? $data['month'] : date('m'), 'sl_month');?>
                &nbsp;&nbsp;&nbsp;
                <?php echo $fview->selectType($year, @$data['year'] ? $data['year'] : date('Y'), 'sl_year');?>
            </span>
        </p>
        
        <p>
        	<label>Khu vực áp dụng</label>
            <span class="formwrapper">
                <?php echo $fview->inputRadio(array(array('id' => 'p1', 'value' => 0, 'label' => 'Toàn quốc &nbsp; &nbsp;'), array('id' => 'p2', 'value' => 1, 'label' => 'Chọn tỉnh')), $data['province_id'], 'province_apply');?>
            </span>
        </p>
        <p id="province_select_box">
            <label>Tỉnh áp dụng</label>
            <span class="formwrapper">
                  <?php echo $fview->multiSelectType($province, $data['id_province'], 'province', 'Chọn tỉnh / thành phố');?>
            </span>
        </p>
        
        <p>
        	<label>Chọn đối tượng ưu đãi</label>
            <span class="formwrapper">
                <?php echo $fview->inputRadio(array(array('id' => 'r1', 'value' => 0, 'label' => 'Chọn tất cả &nbsp; &nbsp;'), array('id' => 'r2', 'value' => 1, 'label' => 'Một hoặc nhiều nhà hàng')), $data['type_sl'], 'restaurant_target');?>
            </span>
        </p>
        <p id="restaurant_select_box">
        	<label>Lựa chọn nhà hàng</label>
            <span class="formwrapper">
                  <?php echo $fview->multiSelectType($arrRestaurant, $data['id_restaurant'], 'restaurants', 'Chọn nhà hàng');?>
            </span>
        </p>
		<p>
        	<label>Là ưu đãi đối tác</label>
            <span class="field">
                <input type="checkbox" name="is_partner" id="active" <?php echo $data['is_partner'] == 1 ? 'checked="checked"' : ''?> class="input-small" placeholder="Trạng thái" <?php echo $this->input->post('is_partner') == 1 ? 'checked="checked"' : '' ;?> value="1"/>
                Kích hoạt ưu đãi đối tác
            </span>
        </p>
		<p>
        	<label>Thứ tự sắp xếp</label>
            <span class="field"><input type="number" name="orderby" class="input-xlarge" placeholder="Thứ tự sắp xếp" value="<?php echo $data['orderby'];?>"/></span>
        </p>
		<p>
        	<label>Trạng thái ( * )</label>
            <span class="field">
                <input type="checkbox" name="active" id="active" <?php echo $data['active'] == 1 ? 'checked="checked"' : ''?> class="input-small" placeholder="Trạng thái" <?php echo $this->input->post('active') == 1 ? 'checked="checked"' : '' ;?> value="1"/>
                Kích hoạt
            </span>
        </p>
        <p>
            <label></label>
            <button class="btn btn-rounded" type="submit"> <i class="iconfa-ok"></i> &nbsp; Lưu</button>
        </p>
    </form>
    
    </div>
</div>




<script>

function convertimage(id, id_parse, img_show, check_image)
{
    var id = id;
    var id_parse = id_parse;
    var img_show = img_show;
    var check_image = check_image;
    var filesSelected = document.getElementById(id).files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) 
        {
            $("#"+id_parse).attr('value', fileLoadedEvent.target.result);
            $("#"+check_image).val('1');
            //document.getElementById('cddd').html(fileLoadedEvent.target.result);
            $("#"+img_show).attr('src', fileLoadedEvent.target.result);
        };

        fileReader.readAsDataURL(fileToLoad);
    }
}

$(function()
{   
    if($('#x2').is(':checked'))
    {
        $('#time_select_box').show();
    }else{
        $('#time_select_box').hide();
    }
    $('input[type=radio][name=incentives_type]').change(function()
    {
        var type = this.value;
        
        if(type == 1){
            $('#time_select_box').fadeIn('slow');    
        }else{
            $('#time_select_box').fadeOut('slow');
        }
    });
});
$(function()
{
    if($('#r2').is(':checked'))
    {
        $('#restaurant_select_box').show();
    }else{
        $('#restaurant_select_box').hide();
    }
    $('input[type=radio][name=restaurant_target]').change(function()
    {
        var r_type = this.value;
        
        if(r_type == 1){
            $('#restaurant_select_box').fadeIn('slow');
        }else{
            $('#restaurant_select_box').fadeOut('slow');
        }
    });
});
$(function()
{
    if($('#p2').is(':checked'))
    {
        $('#province_select_box').show();
    }else{
        $('#province_select_box').hide();
    }
    $('input[type=radio][name=province_apply]').change(function()
    {
        var p_type = this.value;
        
        if(p_type == 1){
            $('#province_select_box').fadeIn('slow');
        }else{
            $('#province_select_box').fadeOut('slow');
        }
    });
});
</script>
<script type="text/javascript">
        CKEDITOR.replace( 'content_', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
        CKEDITOR.on( 'instanceReady', function( ev )
        {
         ev.editor.dataProcessor.writer.setRules( 'br',
         {
            indent : false,
            breakBeforeOpen : false,
            breakAfterOpen : false,
            breakBeforeClose : false,
            breakAfterClose : false
		});
		});
</script> 